import Vue from "vue";
import pageing from "../../../components/pageing/pageing.js";
import {request} from "../../../util/request.js";
import "../../../style/basic.less";
new Vue({
    el:"#louie",
    data:{
        returnNum:10,  //请求数据数量
        pageNum:1,  //当前page页面
        total:0,
        list:[]   //列表
    },
    components:{
        page:pageing
    },
    created:function(){
        this.getTotal()
            .then(()=>{
                if(this.total > 0){
                    this.getList();
                }
            })
    },
    methods:{
        /**
         * 获取列表数据总数
         */
        getTotal(){
            return new Promise((success)=>{
                request('member/getTotal')
                    .then((res)=>{
                        if(res.data.status === "success"){
                            this.total = parseInt(res.data.data);
                            success();
                        }
                    });
            });
        },
        /**
         * 获取列表
         */
        getList(){
            request("member/getList",{
                limit:[(this.pageNum-1)*this.returnNum,this.returnNum]
            })
                .then((res)=>{
                    if(res.data.status === "success"){
                        this.list = res.data.data;
                    }
                });
        },
        /**
         * 点击分页
         * @param page
         */
        changePage:function(page){
            this.pageNum = page;
            this.getList();
        }
    }
});